package com.bwhx.eruler.dao.impl;

import java.util.HashMap;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.bwhx.eruler.bean.Page;
import com.bwhx.eruler.bean.Staff;
import com.bwhx.eruler.dao.StaffDao;
import com.bwhx.eruler.util.MD5Utils;

/**
 * @Description:
 */
@Repository
public class StaffDaoImpl extends BaseDaoImpl<Staff> implements StaffDao {
	public StaffDaoImpl() {
		this.setNs("com.bwhx.eruler.mapper.StaffMapper.");
	}


	public List<Staff> findByName(String staffname) {
	
		return getSqlSession().selectList("com.bwhx.eruler.mapper.StaffMapper." + "findByName", staffname);
	}


	@Override
	public synchronized int insertSN() {
		
		
		Object selectOne = getSqlSession().selectOne("com.bwhx.eruler.mapper.StaffMapper." + "getMaxSN");
		if(null!=selectOne && selectOne instanceof Integer){
			int i = (Integer)selectOne+1;
			getSqlSession().insert("com.bwhx.eruler.mapper.StaffMapper." + "insertSN",i);
			return i;
		}
		return -1;
		 
	}


	@Override
	public void inputStaff(Staff s) {
		this.getSqlSession().update("com.bwhx.eruler.mapper.StaffMapper." + "updateruler", s);
		
		
	}

	@Override
	public List<Staff> list(Page p) {
		return getSqlSession().selectList("com.bwhx.eruler.mapper.StaffMapper." + "list",p);

	}


	@Override
	public Integer count(Staff s) {
		Object selectOne = getSqlSession().selectOne("com.bwhx.eruler.mapper.StaffMapper." + "count",s);
		if(null!=selectOne && selectOne instanceof Integer){
			return (int)selectOne;
		}
		return 0;
	}


	@Override
	public Staff login(String loginName, String pwd) {
		 List<Staff> findByName = getSqlSession().selectList("com.bwhx.eruler.mapper.StaffMapper." + "findByLoginName", loginName);
		if(null!=findByName&&findByName.size()>0 && findByName.get(0).getsPwd().equals(MD5Utils.md5(pwd))){
			return findByName.get(0);
		}else{
			return null;
		}

	}


	@Override
	public List<Staff> listAll() {
		return getSqlSession().selectList("com.bwhx.eruler.mapper.StaffMapper." + "listAll");
	}


	@Override
	public Staff findById(Integer oOKuGuanId) {
		
		return getSqlSession().selectOne("com.bwhx.eruler.mapper.StaffMapper." + "findById",oOKuGuanId);

	}


	@Override
	public Staff findByLoginName(String loginName) {
		
		return  getSqlSession().selectOne("com.bwhx.eruler.mapper.StaffMapper." + "findByLoginName", loginName);
	}


	@Override
	public void updatestaffAuthorization(HashMap<String, Object> paramMap) {
		this.getSqlSession().update("com.bwhx.eruler.mapper.StaffMapper." + "updatestaffAuthorization", paramMap);
	
	}


	@Override
	public void del(String sId) {
		this.getSqlSession().update(this.getNs() + "del", sId);

		
	}


	@Override
	public void changePwd(Staff staff) {
		 this.getSqlSession().update(this.getNs() + "changePwd", staff);
		
	}


	@Override
	public void changePwdByPhone(Staff staff) {
		 this.getSqlSession().update(this.getNs() + "changePwdByPhone", staff);

		
	}


	@Override
	public Staff findByPhone(String getsPhone) {
		return  getSqlSession().selectOne("com.bwhx.eruler.mapper.StaffMapper." + "findByPhone", getsPhone);
	}


	@Override
	public String getName(String uploaderID) {
		return  getSqlSession().selectOne("com.bwhx.eruler.mapper.StaffMapper." + "getName", uploaderID);

	}
	
}
